package asynqQueue

import (
	"context"
	"github.com/gogf/gf/v2/database/gredis"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/util/gconv"
	"github.com/hibiken/asynq"
)

type WorkflowTopicType uint8

const (
	UserConfirmScore WorkflowTopicType = iota // 用户自动确认评分
)

var WorkflowTopicName = map[WorkflowTopicType]string{
	UserConfirmScore: "UserConfirmScore",
}

func GetRedisClientOpt(ctx context.Context) asynq.RedisClientOpt {

	redisTmp, _ := g.Cfg().Get(ctx, "queue.redis", g.Map{})
	redisConfig := new(gredis.Config)
	if err := gconv.Struct(redisTmp, redisConfig); err != nil {
		g.Log().Error(ctx, "asynq init redis conv error ", err)
		panic(err)
	}
	return asynq.RedisClientOpt{
		Addr:     redisConfig.Address,
		Password: redisConfig.Pass,
		DB:       redisConfig.Db,
	}
}
